home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
- Newsgroups: comp.lang.c
- Subject: Re: How do you pass along a variable argument list?
- Date: Thu, 11 Jan 1996 12:38:07 GMT
- Organization: Carelcomp Forest Oy
- Message-ID: <4d30nv$k8r@tahko.lpr.carel.fi>
- References: <4d1i8v$k8h@news.mcl.bdm.com>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- X-Newsreader: Forte Free Agent 1.0.82
-
- ywu@plato.sky.bdm.com wrote:
-
- >Hi, there:
-
- >I am writing a wrapper around a routine which takes variable argument list only. I
- >want my wrapper has the similar prototype and can pass the variable arguments
- >directly to the routine(by the way, I cannot change the code of that routine).
-
- >I guess it is really hard to do it in ANSI, and I know how to do it in a stupid
- >way---but, is there any way around??
-
- >Thanks!!
-
- >Yibing Wu
- >ywu@plato.sky.bdm.com
-
- Actually, it's not so difficult. Here's an ANSI-compliant example that
- wraps the printf function:
-
- #include <stdio.h>
- #include <stdarg.h>
-
- void MyPrintf(char *fmt, ...)
- {
- va_list argp;
-
- va_start(argp, fmt);
- printf(fmt, argp);
- va_end(argp);
- }
-
- An Unix-like version goes like this:
-
- #include <stdio.h>
- #include <varargs.h>
-
- void MyPrintf(va_alist)
- va_dlc /* Observ there's no semicolon here */
- {
- va_list argp;
-
- va_start(argp);
- printf(argp);
- va_end(argp);
- }
-
- HTH,
- Ari Lukumies
-
- All my opinions are mine and mine alone.
-
-